package com.hphs.controller;

import com.hphs.dto.ResponseDTO;
import com.hphs.model.Category;
import com.hphs.model.CategoryQuery;
import com.hphs.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
// 告诉前端 我给你一个地址 就能获取数据 其他不要找我
// http://localhost:8080/api/category
@RestController
@RequestMapping("/api/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //@GetMapping
    public List<Category> findAll(){
        return  categoryService.findAll();
    }
    @GetMapping
    public List<Category> select(CategoryQuery query){
        return categoryService.select(query);
    }
//    @GetMapping
//    public ResponseDTO select(CategoryQuery query){
//        List<Category> select = categoryService.select(query);
//        return ResponseDTO.success(select);
//    }

    //RequestBody  前端提交的数据是json格式的
    @PostMapping
    public Integer insert(@RequestBody Category category){
        return categoryService.insert(category);
    }

    @PutMapping
    public Integer update(@RequestBody Category category){
        return categoryService.update(category);
    }

    @DeleteMapping
    public Integer delete(Integer id){
        return categoryService.updateStatus(id);
    }

}
